package com.qing.microservices.shirostudy.controller;

import com.qing.microservices.shirostudy.entity.Role;
import com.qing.microservices.shirostudy.service.IRoleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Q
 * @since 2023-06-06
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private IRoleService roleService;

    @PostMapping("/addition")
    public void addRole(@RequestBody List<String> roleNames) {
        List<Role> roleList = roleNames.stream().map(s -> {
            Role role = new Role();
            role.setName(s);
            return role;
        }).collect(Collectors.toList());

        roleService.saveBatch(roleList);
    }




}
